package com.jia.controller;

import com.jia.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {
    // 消费者 不应该有service
    // RestTemplate

    @Autowired
    private RestTemplate restTemplate;

    // private static final String PROVIDER_URL_PREFIX="http://localhost:8001/";
    // 通过ribbon
    private static final String PROVIDER_URL_PREFIX="http://SPRINGCLOUD-PROVIDER-DEPT/";

    @GetMapping("/consumer/dept/info/{id}")
    public Dept info(@PathVariable Long id){
        return restTemplate.getForObject(PROVIDER_URL_PREFIX+"dept/info/"+id,Dept.class);
    }
    @GetMapping("/consumer/dept/list")
    public List<Dept> list(){
        return restTemplate.getForObject(PROVIDER_URL_PREFIX+"dept/list",List.class);
    }

    @PostMapping("/consumer/dept/add")
    public int add(Dept dept){
        return restTemplate.postForObject(PROVIDER_URL_PREFIX+"dept/add",dept,Integer.class);
    }

    @PostMapping("/consumer/dept/update")
    public int update(Dept dept){
        return restTemplate.postForObject(PROVIDER_URL_PREFIX+"dept/update",dept,Integer.class);
    }

    @DeleteMapping("/consumer/dept/delete/{id}")
    public int delete(@PathVariable Long id){
        return restTemplate.postForObject(PROVIDER_URL_PREFIX+"dept/delete/",id,Integer.class);
    }


}
